package com.geeka.d12.udp;

import java.io.IOException;
import java.net.*;
import java.nio.charset.StandardCharsets;

public class UdpClient {
    public static void main(String[] args) throws UnknownHostException {
        System.out.println("=====客户端启动=====");

        try {

            // UDP通信类 占据本机的6666端口 发送方
            DatagramSocket socket = new DatagramSocket(6666);
            String str = "你好,UDP";
            byte[] buffer = str.getBytes(StandardCharsets.UTF_8);
            DatagramPacket packet = new DatagramPacket(buffer, buffer.length, InetAddress.getLocalHost(), 8888);

            socket.send(packet);
        } catch (SocketException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
